package com.kldy8.kldyw.live;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.kldy8.kldyw.Main2Activity;
import com.kldy8.kldyw.MyWebActivity;
import com.kldy8.kldyw.R;
import com.kldy8.kldyw.logre.LoginActivity;
import com.kldy8.kldyw.system.UrlBuilder;
import com.kldy8.kldyw.web.MyJavaScriptInterface;

@Deprecated
public class LiveEditStatusActivity extends MyWebActivity
{

    WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live_edit_status);

        webView = (WebView) findViewById(R.id.webView);

        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.addJavascriptInterface(this, "WebViewJavascriptBridge");

        String live_id = getIntent().getStringExtra("live_id");
        String urlString = UrlBuilder.URL_BASE_API+"/live/live_end?live_id="+live_id;
        webView.loadUrl(urlString);



        //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
        webView.setWebViewClient(new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                Log.e("url....",url);
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器

                if (url.equals(UrlBuilder.URL_BASE_API+"/live/live_list"))
                {
                    Intent in = new Intent();
                    in.putExtra( "result", "res" );
                    int abc = 1002;
                    setResult(abc, in );
                    finish();
                }
                if (url.equals(UrlBuilder.URL_BASE_API+"/api/live/edit_status"))
                {
                    Intent in = new Intent();
                    in.putExtra( "result", "res" );
                    int abc = 1002;
                    setResult(abc, in );
                    finish();
                }
                else
                {
                    view.loadUrl(url);
                }
                return true;
            }
        });
    }

    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
        {
            Intent in = new Intent();
            in.putExtra( "result", "res" );
            int abc = 1002;
            setResult(abc, in );
            finish();
        }
        return true;
    }


}
